home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / nut3.cls < prev    next >
Encoding:
Visual Basic class definition  |  2007-02-26  |  53.4 KB  |  1,812 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "Detail"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Option Explicit
  15. '/******************************************************************/
  16. '/*                                                                */
  17. '/*                      TurboCAD for Windows                      */
  18. '/*                   Copyright (c) 1993 - 2001                    */
  19. '/*             International Microcomputer Software, Inc.         */
  20. '/*                            (IMSI)                              */
  21. '/*                      All rights reserved.                      */
  22. '/*                                                                */
  23. '/******************************************************************/
  24.  
  25. 'DBAPI constants
  26. Const gkGraphic = 11
  27. Const gkArc = 2
  28. Const gkText = 6
  29. Const gfCosmetic = 128&
  30.                                                                                                                                                                                              
  31. 'Useful math constants
  32. Const Pi# = 3.14159265
  33. Const Eps = 0.0001
  34.  
  35. 'Real variant types!
  36. Const typeEmpty = 0
  37. Const typeInteger = 2
  38. Const typeLong = 3
  39. Const typeSingle = 4
  40. Const typeDouble = 5
  41. Const typeCurrency = 6
  42. Const typeDate = 7
  43. Const typeString = 8
  44. Const typeObject = 9
  45. Const typeBoolean = 11
  46. Const typeVariant = 12
  47. Const typeIntegerEnum = typeInteger + 100
  48. Const typeLongEnum = typeLong + 100
  49. Const typeStringEnum = typeString + 100
  50.  
  51. 'Stock property pages
  52. Const ppStockPen = 1
  53. Const ppStockBrush = 2
  54. Const ppStockText = 4
  55. Const ppStockInsert = 8
  56. Const ppStockViewport = 16
  57. Const ppStockAuto = 32
  58.  
  59. 'Property Ids
  60. Const idNutType = 1
  61. Const idDiameter = 2
  62. Const idSolid = 3
  63.  
  64. Const idNutTypeOld = 4
  65. Const idDiameterOld = 5
  66. Const idSolidOld = 6
  67.  
  68. Const idHOld = 7
  69.  
  70. 'Property enums
  71.  
  72.  
  73. 'Number of properties, pages, wizards
  74. Const NUM_PROPERTIES = 7
  75. Const NUM_PAGES = 1
  76. Const NUM_WIZARDS = 0
  77.  
  78.  
  79. Private Sub Class_Initialize()
  80.     'Initialize class variables
  81. End Sub
  82.  
  83. 'Returns the user-visible description of this RegenMethod
  84. Public Property Get Description() As String
  85.     Description = "SDK Nut3D"
  86. End Property
  87.  
  88. 'Returns the persistent class id for this RegenMethod's property section
  89. Public Property Get ClassID() As String
  90.     ClassID = "{FDB6F1C3-9631-11d1-A40A-0000B465872B}"
  91. End Property
  92.  
  93. 'Retrieve types and names
  94. Public Function GetPropertyInfo(Names As Variant, Types As Variant, _
  95.     IDs As Variant, Defaults As Variant) As Long
  96.     ReDim Names(NUM_PROPERTIES), Types(NUM_PROPERTIES), _
  97.         IDs(NUM_PROPERTIES), Defaults(NUM_PROPERTIES)
  98.     Names(0) = "NutType"
  99.     Types(0) = typeString
  100.     IDs(0) = idNutType
  101.     Defaults(0) = "HexNut" '"HexSlottedNut"
  102.         
  103.     Names(1) = "Diameter"
  104.     Types(1) = typeDouble
  105.     IDs(1) = idDiameter
  106.     Defaults(1) = 1#
  107.  
  108.     Names(2) = "NutSolid"
  109.     Types(2) = typeInteger
  110.     IDs(2) = idSolid
  111.     Defaults(2) = 0
  112.     
  113.     Names(3) = "NutTypeOld"
  114.     Types(3) = typeString
  115.     IDs(3) = idNutTypeOld
  116.     Defaults(3) = "HexNut" '"HexSlottedNut"
  117.         
  118.     Names(4) = "DiameterOld"
  119.     Types(4) = typeDouble
  120.     IDs(4) = idDiameterOld
  121.     Defaults(4) = 1.5
  122.  
  123.     Names(5) = "NutSolidOld"
  124.     Types(5) = typeInteger
  125.     IDs(5) = idSolidOld
  126.     Defaults(5) = 0
  127.    
  128.     Names(6) = "HOld"
  129.     Types(6) = typeDouble
  130.     IDs(6) = idHOld
  131.     Defaults(6) = 0#
  132.    
  133.    GetPropertyInfo = NUM_PROPERTIES
  134. End Function
  135.  
  136. 'Get the number of property pages supporting this RegenMethod
  137. Public Function GetPageInfo(ByVal AGraphic As Object, StockPages As Long, _
  138.     Names As Variant) As Long
  139.     ReDim Names(NUM_PAGES)
  140.  
  141.     'Need the form
  142. '    Load frmNut3
  143. '    Names(0) = frmNut3.Caption
  144. '    Unload frmNut3
  145.     Names(0) = LoadResString(101)
  146.     StockPages = ppStockBrush + ppStockPen + ppStockAuto
  147.     GetPageInfo = NUM_PAGES
  148. End Function
  149.  
  150. Public Function GetWizardInfo(Names As Variant) As Long
  151.     ReDim Names(NUM_WIZARDS)
  152.     GetWizardInfo = NUM_WIZARDS
  153. End Function
  154.  
  155. 'Enumerate the names and values of a specified property
  156. Public Function GetEnumNames(ByVal PropID As Long, Names As Variant, Values As Variant) As Long
  157.  
  158. End Function
  159.  
  160. Public Function PageControls(ByVal ThisRegenMethod As Object, ByVal Graphic As Object, ByVal PageNumber As Long, ByVal SaveProperties As Boolean) As Boolean
  161.         'Set up error function
  162.         On Error GoTo Failed
  163.         Dim i%
  164.         Dim Diameter#
  165.         Dim SSolid%
  166.         If SaveProperties Then
  167.             'OK button on property page was clicked
  168.             'Form is still loaded
  169.             With frmNut3
  170.                 'Need On Error statement for the case where you have
  171.                 'RRect Turbo Shape and ahother "shape" selected
  172.                 On Error Resume Next
  173.                 'When the property page is closed, transfer the numeric
  174.                 'Diameter value from the TextBox to the Graphic
  175.                 'Get the value as a double-precision number
  176.                 TypeN = .List1.Text
  177.                 Diameter# = CDbl(.txtdd.Text)
  178.                  If .Surf_Solid.Value = True Then
  179.                     SSolid = False
  180.                  ElseIf .Surf_Solid1.Value = True Then
  181.                     SSolid = True
  182.                  End If
  183.                 
  184.                 'Set the property values in the Graphic
  185.                 Graphic.Properties("Diameter") = Diameter#
  186.                 Graphic.Properties("NutType") = TypeN
  187.                 Graphic.Properties("NutSolid") = SSolid
  188.                 
  189.             End With
  190.         Else
  191.             'Property page is about to be opened
  192.             'Make sure the form is loaded
  193.             Load frmNut3
  194.             With frmNut3
  195.             
  196.                 'If more than one RRect is selected and they do not
  197.                 'have the same properties, don't set up this field
  198.                 On Error GoTo NoRType
  199.  
  200.                 'When the property page is opening, transfer the numeric
  201.                 'roundness value from the Graphic to the TextBox
  202.                 'Get the roundness property value from the Graphic
  203.                 Diameter# = Graphic.Properties("Diameter")
  204.                 TypeN = Graphic.Properties("NutType")
  205.                 SSolid = Graphic.Properties("NutSolid")
  206.             'Set the TextBox control's text
  207.                 .txtdd.Text = Diameter#
  208.                 .List1.Text = TypeN
  209.                  If SSolid = True Then
  210.                     .Surf_Solid1.Value = True
  211.                     .Surf_Solid.Value = False
  212.                  ElseIf SSolid = False Then
  213.                     .Surf_Solid1.Value = False
  214.                     .Surf_Solid.Value = True
  215.                  End If
  216.  
  217. NoRType:
  218.             End With
  219.         End If
  220.  
  221.         PageControls = True
  222.         Exit Function
  223.  
  224. Failed:
  225.         'For debugging purposes, report that an error occurred
  226.         If Err.Number <> 0 Then
  227.             MsgBox "Error in PageControls: " & Err.Description
  228.         End If
  229.  
  230.         'Return false if an error occurred
  231.         PageControls = False
  232. End Function
  233.  
  234. Public Function PageDone(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant)
  235.         'Done with form
  236.         Unload frmNut3
  237. End Function
  238.  
  239. Public Function PropertyPages(ByVal ThisRegenMethod As Object, Optional PageNumber As Variant) As Boolean
  240.     With frmNut3
  241.         .Show vbModal
  242.         PropertyPages = Not .DialogCanceled
  243.     End With
  244. End Function
  245.  
  246. Public Function Wizard(ByVal ThisRegenMethod As Object, Optional WizardNumber As Variant) As Boolean
  247.     Wizard = False
  248. End Function
  249.  
  250. 'Called when vertex has been moved, or other geometry change
  251. Public Function OnGeometryChanged(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant)
  252.     'Do nothing
  253.     'Regen Graphic
  254. End Function
  255.  
  256. 'Called when vertex is moved, or other geometry change
  257. Public Function OnGeometryChanging(ByVal Graphic As Object, ByVal GeomID As Long, paramOld As Variant, paramNew As Variant) As Boolean
  258.     'OK to continue with change
  259.     OnGeometryChanging = True
  260. End Function
  261.  
  262. Public Function OnNewGraphic(ByVal grfThis1 As Object, ByVal boolCopy As Boolean) As Boolean
  263.     If boolCopy Then
  264.         'Vertices are already added for us...
  265.         OnNewGraphic = True
  266.         Exit Function
  267.     End If
  268. Dim grfThis As Graphic
  269.     Set grfThis = grfThis1
  270.     If grfThis.Application.ActiveDrawing.Properties("TileMode") <> imsiModelSpace Then
  271.         GoTo Failed
  272.     End If
  273.     On Error GoTo Failed
  274.     'New Graphic being created
  275.     'X, Y, Z, PenDown, Selectable, Snappable, Editable, Linkable
  276.     'First Vertex is "first point of axis"
  277.     grfThis.Vertices.Add 3#, 5#, 0#
  278.     
  279.     'Second Vertex is "Second point of axis"
  280.     grfThis.Vertices.Add 4#, 5#, 0#, False
  281.     OnNewGraphic = True
  282.     Exit Function
  283.  
  284. Failed:
  285.     'Return false on failure
  286.     OnNewGraphic = False
  287. End Function
  288.  
  289. 'Function called whenever a copy of a graphic is being made
  290. Public Function OnCopyGraphic(ByVal grfCopy As Object, ByVal grfSource As Object) As Boolean
  291.     'Return false on failure
  292.     OnCopyGraphic = True
  293. End Function
  294.  
  295. 'Notification function called after graphic property is saved
  296. Public Function OnPropertyChanged(ByVal Graphic As Object, ByVal PropID As Long, _
  297.         ValueOld As Variant, ValueNew As Variant)
  298.     'Do nothing
  299. End Function
  300.  
  301. 'Notification function called when graphic property is saved
  302. Public Function OnPropertyChanging(ByVal Graphic As Object, ByVal PropID As Long, _
  303.         ValueOld As Variant, ValueNew As Variant) As Boolean
  304.     'OK to proceed
  305.     OnPropertyChanging = True
  306. End Function
  307.  
  308. 'Notification function called when graphic property is retrieved
  309. Public Function OnPropertyGet(ByVal Graphic As Object, ByVal PropID As Long)
  310.     'Do nothing
  311. End Function
  312.  
  313. 'Called when we need to update our object
  314. Public Function Regen(ByVal grfThis1 As Object)
  315. 'Setup error handler
  316.         On Error GoTo Failed
  317. Dim grfThis As Graphic
  318.         Set grfThis = grfThis1
  319.         'Set up lock (prevent recursion)
  320.         Dim LockCount&
  321.         LockCount& = grfThis.RegenLock
  322.         'Setup error handler (make sure lock is removed)
  323.         On Error GoTo FailedLock
  324.         If LockCount& = 0 Then
  325. Dim TypeNn As String
  326.             'Delete any previous cosmetic children
  327.             TypeNn = grfThis.Properties("NutType")
  328. Dim TypeNOld$
  329.             TypeNOld = grfThis.Properties("NutTypeOld")
  330. Dim dd#, ddOld#
  331.             dd = grfThis.Properties("Diameter")
  332.             ddOld = grfThis.Properties("DiameterOld")
  333. Dim NSolid%, NSolidOld%
  334.             NSolid = grfThis.Properties("NutSolid")
  335.             NSolidOld = grfThis.Properties("NutSolidOld")
  336. Dim Salp#, Calp#, L#
  337. Dim X00#, Y00#, Z00#, X01#, Y01#, Z01#
  338.             grfThis.Vertices.UseWorldCS = True
  339.             With grfThis.Vertices
  340.                 X00 = .Item(0).X
  341.                 Y00 = .Item(0).Y
  342.                 Z00 = .Item(0).Z
  343.                 X01 = .Item(1).X
  344.                 Y01 = .Item(1).Y
  345.                 Z01 = .Item(1).Z
  346.             End With
  347.             
  348. 'Block to snap to Bolt's axis
  349. 'Dim GrSet As GraphicSet
  350. 'Dim CountGr As Long
  351. 'Dim i As Long
  352. 'Dim Gr1 As Graphic
  353. 'Dim X10#, Y10#, Z10#, X11#, Y11#, Z11#
  354. '            Set GrSet = grfThis.Drawing.Graphics.QuerySet("Type=SDK_Bolt_Screw")
  355. '            CountGr = GrSet.Count
  356. '            For i = 0 To CountGr - 1
  357. '                Set Gr1 = GrSet(i)
  358. '                If Gr1.Type = "HexBolt3D.Detail" Then
  359. '                    Gr1.Vertices.UseWorldCS = True
  360. '                    With Gr1.Vertices
  361. '                        X10 = .Item(0).X
  362. '                        Y10 = .Item(0).Y
  363. '                        Z10 = .Item(0).Z
  364. '                        X11 = .Item(1).X
  365. '                        Y11 = .Item(1).Y
  366. '                        Z11 = .Item(1).Z
  367. '                    End With
  368. 'Dim s#
  369. '                    s = DistPointLine(X00, Y00, Z00, X10, Y10, Z10, X11, Y11, Z11)
  370. '                    If Abs(s) < -0.1 Then
  371. 'Dim hNut#, lBolt#, lBoltNut#
  372. '                        hNut = grfThis.Properties("HOld")
  373. '                        lBolt = Sqr((X11 - X10) * (X11 - X10) + (Y11 - Y10) * (Y11 - Y10) + (Z11 - Z10) * (Z11 - Z10))
  374. '                        lBoltNut = Sqr((X00 - X10) * (X00 - X10) + (Y00 - Y10) * (Y00 - Y10) + (Z00 - Z10) * (Z00 - Z10))
  375. '                        If hNut < Eps Or lBoltNut < Eps Then
  376. '                            Exit For
  377. '                        End If
  378. 'Dim X00New#, Y00New#, Z00New#, X01New#, Y01New#, Z01New#
  379. '                        X00New = X10 + (X11 - X10) * lBoltNut / lBolt
  380. '                        Y00New = Y10 + (Y11 - Y10) * lBoltNut / lBolt
  381. '                        Z00New = Z10 + (Z11 - Z10) * lBoltNut / lBolt
  382. '                        X01New = X00New + (X11 - X10) * hNut / lBolt
  383. '                        Y01New = Y00New + (Y11 - Y10) * hNut / lBolt
  384. '                        Z01New = Z00New + (Z11 - Z10) * hNut / lBolt
  385. '                        grfThis.MoveRelative X00New - X00, Y00New - Y00, Z00New - Z00
  386. 'Dim xTo#, yTo#, zTo#
  387. 'Dim xFrom#, yFrom#, zFrom#
  388. 'Dim xRef#, yRef#, zRef#
  389. '                        xRef = X00New
  390. '                        yRef = Y00New
  391. '                        zRef = Z00New
  392.  
  393. '                        xTo = X00New + (X01 - X00) / hNut
  394. '                        yTo = Y00New + (Y01 - Y00) / hNut
  395. '                        zTo = Z00New + (Z01 - Z00) / hNut
  396.  
  397. '                        xFrom = X00New + (X01New - X00New) / hNut
  398. '                        yFrom = Y00New + (Y01New - Y00New) / hNut
  399. '                        zFrom = Z00New + (Z01New - Z00New) / hNut
  400. '                        grfThis.RotateAbsolute xTo, yTo, zTo, xFrom, yFrom, zFrom, xRef, yRef, zRef
  401. '                        Salp = (Y01 - Y00) / hNut
  402. '                        Calp = (X01 - X00) / hNut
  403. 'Dim beta#
  404. '                        beta = Angle(Salp, Calp)
  405. '
  406. '                       Exit For
  407. '                    End If
  408. '                End If
  409. '            Next i
  410. '            Set Gr1 = Nothing
  411. '            Set GrSet = Nothing
  412.  
  413.             L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00) + (Z01 - Z00) * (Z01 - Z00))
  414.             Salp = (Y01 - Y00) / L
  415.             Calp = (X01 - X00) / L
  416.  Dim HOld#
  417.             HOld = grfThis.Properties("HOld")
  418.            
  419. '##########################################################
  420. Dim CountCosm As Long, iCosm As Long
  421.             CountCosm = grfThis.Graphics.Count
  422.             If CountCosm > 1 Then
  423.                 For iCosm = 1 To CountCosm - 1
  424.                     grfThis.Graphics(iCosm).Properties("PenColor") = grfThis.Properties("PenColor")
  425.                 Next iCosm
  426.             End If
  427.             If grfThis.Properties("Selected") = False Or Abs(L - HOld) > Eps Or CountCosm < 2 Or NSolid <> NSolidOld Or Abs(dd - ddOld) > Eps Or TypeNn <> TypeNOld Then
  428.                 grfThis.Graphics.Clear gfCosmetic
  429. ' Block for Scaling
  430. Dim AddScale#
  431.                 AddScale = 1
  432.                 dd = dd * AddScale
  433.             
  434.                 If TypeNn = "HexNut" Then
  435.                     Call HexNut(grfThis, dd, Salp, Calp, NSolid, AddScale)
  436.                 End If
  437.                 
  438.                 If TypeNn = "HexSlottedNut" Then
  439.                     Call HexSlottedNut(grfThis, dd, Salp, Calp, NSolid, AddScale)
  440.                 End If
  441.                 
  442.                 If TypeNn = "LowCrownNut" Then
  443.                     Call LowCrownNut(grfThis, dd, Salp, Calp, NSolid, AddScale)
  444.                 End If
  445. ' Block for Unscaling
  446.                 dd = dd / AddScale
  447. 'Dim Matr As Matrix
  448.                 
  449.                 grfThis.Properties("DiameterOld") = dd
  450.                 grfThis.Properties("NutTypeOld") = TypeNn
  451.                 grfThis.Properties("NutSolidOld") = NSolid
  452.                 
  453.                 grfThis.Vertices.UseWorldCS = True
  454.                 With grfThis.Vertices
  455.                     X00 = .Item(0).X
  456.                     Y00 = .Item(0).Y
  457.                     Z00 = .Item(0).Z
  458.                     X01 = .Item(1).X
  459.                     Y01 = .Item(1).Y
  460.                     Z01 = .Item(1).Z
  461.                     L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00) + (Z01 - Z00) * (Z01 - Z00))
  462.                 End With
  463.                 grfThis.Properties("HOld") = L
  464.             End If
  465.             'Add visible child Graphics
  466.         End If
  467.         grfThis.RegenUnlock
  468.         Exit Function
  469.  
  470. FailedLock:
  471.         'Remove lock
  472.         grfThis.RegenUnlock
  473.  
  474. Failed:
  475. End Function
  476.  
  477. Public Function Draw(ByVal grfThis As Object, ByVal view As Object, Optional mat As Variant) As Boolean
  478.     'Return True if we did the redraw (no further processing necessary, no children will be drawn).
  479.     'Since this is just a test, we return False to let TurboCAD do the drawing operation.
  480.     Draw = False
  481. End Function
  482. Private Function Angle(sinb As Double, cosb As Double) As Double
  483.  
  484.         If Abs(cosb) < 0.0001 Then
  485.             If sinb > 0 Then
  486.                 Angle = Pi / 2
  487.             Else
  488.                 Angle = 3 * Pi / 2
  489.             End If
  490.         Else
  491.             If sinb >= 0 And cosb > 0 Then Angle = Atn(sinb / cosb)
  492.             If sinb >= 0 And cosb < 0 Then Angle = Pi + Atn(sinb / cosb)
  493.             If sinb < 0 And cosb < 0 Then Angle = Pi + Atn(sinb / cosb)
  494.             If sinb < 0 And cosb > 0 Then Angle = 2 * Pi + Atn(sinb / cosb)
  495.         End If
  496. End Function
  497.  
  498.  
  499.  
  500.  
  501. ' HexNut
  502.  
  503. Private Sub HexNut(Gr As Graphic, dd As Double, Salp As Double, Calp As Double, SSolid As Integer, AddScale As Double)
  504. On Error GoTo Failed
  505. Dim Grs As Graphics
  506.     Set Grs = Gr.Application.ActiveDrawing.Graphics
  507. Dim D#, H#, s#, del#
  508.         D = 1.84 * dd
  509.         H = 0.7 * dd
  510.         s = D * Cos(Pi / 6)
  511.         del = 0.1 * dd
  512.         
  513.         Gr.Vertices.UseWorldCS = True
  514.         
  515. Dim X00#, Y00#, Z00#, X01#, Y01#, Z01#, L#
  516.         
  517.         With Gr.Vertices
  518.             X00 = .Item(0).X
  519.             Y00 = .Item(0).Y
  520.             Z00 = .Item(0).Z
  521.             X01 = .Item(1).X
  522.             Y01 = .Item(1).Y
  523.             Z01 = .Item(1).Z
  524.             L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00) + (Z01 - Z00) * (Z01 - Z00)) '!!!!!!!
  525.             .Item(1).X = X00 + (X01 - X00) * H / AddScale / L
  526.             .Item(1).Y = Y00 + (Y01 - Y00) * H / AddScale / L
  527.             .Item(1).Z = Z00 + (Z01 - Z00) * H / AddScale / L
  528.             X01 = X00 + (X01 - X00) * H / L '!!!!!!!
  529.             Y01 = Y00 + (Y01 - Y00) * H / L '!!!!!!!
  530.             Z01 = Z00 + (Z01 - Z00) * H / L '!!!!!!!
  531.         End With
  532.  
  533.         
  534. Dim X00New#, Y00New#, Z00New#, X01New#, Y01New#, Z01New#
  535.         X00New = X00    '!!!!!!!
  536.         Y00New = Y00    '!!!!!!!
  537.         Z00New = Z00    '!!!!!!!
  538.         X01New = X01    '!!!!!!!
  539.         Y01New = Y01    '!!!!!!!
  540.         Z01New = Z01    '!!!!!!!
  541.         X00 = 0#    '!!!!!!!
  542.         Y00 = 0#    '!!!!!!!
  543.         Z00 = 0#    '!!!!!!!
  544.         X01 = H    '!!!!!!!
  545.         Y01 = 0#    '!!!!!!!
  546.         Z01 = 0#    '!!!!!!!
  547.         
  548. Dim x0(100)
  549. Dim y0(100)
  550. Dim X(100)
  551. Dim Y(100)
  552.        
  553.  
  554. Dim i As Long
  555. ' Head of the bolt
  556.     For i = 7 To 13
  557.         x0(i) = D / 2 * Cos(Pi / 3 * (i - 7))
  558.         y0(i) = D / 2 * Sin(Pi / 3 * (i - 7))
  559.     Next i
  560. Dim Gr1 As Graphic
  561. Set Gr1 = Grs.Add(gkGraphic)
  562. Gr1.Vertices.UseWorldCS = True
  563. With Gr1.Vertices
  564.     For i = 7 To 13
  565.         .Add x0(i), y0(i), 0
  566.     Next i
  567. End With
  568. Gr1.Closed = True
  569. Gr1.Properties("Thickness") = H
  570. Gr1.Properties("Solid") = SSolid
  571. Dim xTo#, yTo#, zTo#, xFrom#, yFrom#, zFrom#, xRef#, yRef#, zRef#
  572.     xTo = X00 + (X01 - X00) / H
  573.     yTo = Y00 + (Y01 - Y00) / H
  574.     zTo = 0
  575.     xFrom = X00
  576.     yFrom = Y00
  577.     zFrom = -1#
  578.     xRef = X00
  579.     yRef = Y00
  580.     zRef = 0#
  581.     Gr1.RotateAbsolute xTo, yTo, zTo, xFrom, yFrom, zFrom, xRef, yRef, zRef
  582.     Gr1.Draw
  583. '################################################################
  584. '################################################################
  585. Dim T#
  586.     T = D / 2 * Sin(Pi / 3)
  587.        x0(1) = -0.1 * H
  588.        y0(1) = T * 0.7 - 0.1 * H / Tan(Pi / 6)
  589.        
  590.        x0(2) = -0.1 * H
  591.        y0(2) = D
  592.        
  593.        x0(3) = 0.4 * H
  594.        y0(3) = D
  595.        
  596.        x0(4) = 0.4 * H
  597.        y0(4) = T * 0.7 + 0.5 * H / Tan(Pi / 6)
  598.        
  599.        x0(5) = x0(1)
  600.        y0(5) = y0(1)
  601.        
  602. '-----------------------------------------------------------
  603.        
  604. Dim GrTemp As Graphic
  605.             Set GrTemp = Grs.Add(gkGraphic)
  606. GrTemp.Vertices.UseWorldCS = True
  607.             With GrTemp.Vertices
  608.                 For i = 1 To 5
  609.                     .Add x0(i), y0(i), 0
  610.                 Next i
  611.             End With
  612.             GrTemp.Closed = True
  613. Dim Gr2 As Graphic '1 faska
  614.             Set Gr2 = Grs.Add(, "TCW40SPIN")
  615. Gr2.Vertices.UseWorldCS = True
  616.             Gr2.Properties("Solid") = SSolid
  617.             Gr2.Properties("$ROTATIONANGLE") = 2 * Pi
  618.             Gr2.Properties("$ROTATIONCOPY") = 30
  619.             Set GrTemp = Grs.Remove(GrTemp.Index)
  620.             Gr2.Graphics.AddGraphic GrTemp
  621.             Gr2.Vertices.Add X00, Y00, 0
  622.             Gr2.Vertices.Add X01, Y01, 0
  623.             Gr2.Draw
  624. Dim Gr3 As Graphic ' 2 faska
  625.             Set Gr3 = Gr2.Duplicate
  626.             Gr3.RotateAxis Pi, 0, 0, 1, X00, Y00, Z00
  627.             Gr3.MoveRelative H, 0, 0
  628.             Gr3.Draw
  629. ' Internal Hole
  630.        x0(1) = -del
  631.        y0(1) = 0#
  632.        
  633.        x0(2) = -del
  634.        y0(2) = dd / 2 + del
  635.        
  636.        x0(3) = del
  637.        y0(3) = dd / 2 - del
  638.        
  639.        x0(4) = H - del
  640.        y0(4) = dd / 2 - del
  641.        
  642.        x0(5) = H + del
  643.        y0(5) = dd / 2 + del
  644.        
  645.        x0(6) = H + del
  646.        y0(6) = 0
  647.        
  648.        x0(7) = x0(1)
  649.        y0(7) = y0(1)
  650.        
  651. '-----------------------------------------------------------
  652.        
  653.             Set GrTemp = Grs.Add(gkGraphic)
  654. GrTemp.Vertices.UseWorldCS = True
  655.             With GrTemp.Vertices
  656.                 For i = 1 To 7
  657.                     .Add x0(i), y0(i), 0
  658.                 Next i
  659.             End With
  660.             GrTemp.Closed = True
  661. Dim Gr4 As Graphic
  662.             Set Gr4 = Grs.Add(, "TCW40SPIN")
  663. Gr4.Vertices.UseWorldCS = True
  664.             Gr4.Properties("Solid") = SSolid
  665.             Gr4.Properties("$ROTATIONANGLE") = 2 * Pi
  666.             Gr4.Properties("$ROTATIONCOPY") = 30
  667.             Set GrTemp = Grs.Remove(GrTemp.Index)
  668.             Gr4.Graphics.AddGraphic GrTemp
  669.             Gr4.Vertices.Add X00, Y00, 0, False, False, False, False, False
  670.             Gr4.Vertices.Add X01, Y01, 0, False, False, False, False, False
  671.             Gr4.Draw
  672. ' Thread
  673.     'Base contour
  674. Dim hThread# ' Step of the thread
  675.     hThread = del / Sin(Pi / 3)
  676. Dim nCoil As Long
  677.     nCoil = 10
  678.     nCoil = CLng(H / hThread) + 2
  679. Dim lThread#
  680.     lThread = nCoil * hThread
  681. Dim k As Long
  682.     
  683.     x0(1) = 0 '  hThread
  684.     y0(1) = 0#
  685.     
  686.     x0(2) = 0 '  hThread
  687.     y0(2) = dd / 2 - del
  688.     
  689.     k = 2
  690.     
  691.     For i = 1 To nCoil
  692.         k = k + 1
  693.         x0(k) = x0(k - 1) + hThread / 2
  694.         y0(k) = y0(k - 1) + del
  695.         k = k + 1
  696.         x0(k) = x0(k - 1) + hThread / 2
  697.         y0(k) = y0(k - 1) - del
  698.     Next i
  699.     k = k + 1
  700.     x0(k) = x0(k - 1)
  701.     y0(k) = 0
  702.     
  703.     k = k + 1
  704.     x0(k) = 0
  705.     y0(k) = 0
  706.  
  707. Set GrTemp = Grs.Add(gkGraphic)
  708. GrTemp.Vertices.UseWorldCS = True
  709. With GrTemp.Vertices
  710.     For i = 1 To k '6
  711.         .Add x0(i), y0(i), 0
  712.     Next i
  713. End With
  714. GrTemp.Closed = True
  715. GrTemp.MoveRelative -hThread, 0, 0
  716. GrTemp.Draw
  717. Dim Gr5 As Graphic
  718. Set Gr5 = Grs.Add(, "TCW40SPIN")
  719. Gr5.Vertices.UseWorldCS = True
  720. Gr5.Properties("Solid") = SSolid
  721. Gr5.Properties("$ROTATIONANGLE") = 2 * Pi
  722. Gr5.Properties("$ROTATIONCOPY") = 30
  723. Set GrTemp = Grs.Remove(GrTemp.Index)
  724. Gr5.Graphics.AddGraphic GrTemp
  725. Gr5.Vertices.Add X00, Y00, 0, False, False, False, False, False
  726. Gr5.Vertices.Add X01, Y01, 0, False, False, False, False, False
  727. Gr5.Draw
  728.  
  729. '#################################################################
  730. '################################################################
  731. Dim Bool3D As Boolean3D
  732. Dim GrRes1 As Graphic
  733. Dim GrIndex As Long
  734.     Set Bool3D = New Boolean3D
  735. '    Gr1.Draw
  736. '    Gr2.Draw
  737. 'MsgBox ("1111")
  738.     Set GrRes1 = Bool3D.Subtract(Gr1, Gr2)
  739. 'MsgBox (GrRes1.Type)
  740.     If (Not GrRes1 Is Nothing) Then
  741.         Gr1.Visible = False
  742.         Gr1.Draw
  743.         Gr1.Deleted = True
  744.         Gr2.Visible = False
  745.         Gr2.Draw
  746.         Gr2.Deleted = True
  747.         Grs.AddGraphic GrRes1
  748. 'MsgBox ("@@@@")
  749.     Else
  750.         GrIndex = Gr2.Index
  751.         Grs.Remove GrIndex
  752.         Gr.Graphics.AddGraphic Gr2
  753.         Gr2.Cosmetic = True
  754.         Set GrRes1 = Gr1
  755.     End If
  756. Dim GrRes2 As Graphic
  757.     GrRes1.Draw
  758.     Set GrRes2 = Bool3D.Subtract(GrRes1, Gr3)
  759.     If (Not GrRes2 Is Nothing) Then
  760.         GrRes1.Visible = False
  761.         GrRes1.Draw
  762.         GrRes1.Deleted = True
  763.         Gr3.Visible = False
  764.         Gr3.Draw
  765.         Gr3.Deleted = True
  766.         Grs.AddGraphic GrRes2
  767.     Else
  768.         GrIndex = Gr3.Index
  769.         Grs.Remove GrIndex
  770.         Gr.Graphics.AddGraphic Gr3
  771.         Gr3.Cosmetic = True
  772.         Set GrRes2 = GrRes1
  773.     End If
  774.     
  775. Dim GrRes3 As Graphic
  776.     GrRes2.Draw
  777.     Set GrRes3 = Bool3D.Subtract(GrRes2, Gr4)
  778.     If (Not GrRes3 Is Nothing) Then
  779.         GrRes2.Visible = False
  780.         GrRes2.Draw
  781.         GrRes2.Deleted = True
  782.         Gr4.Visible = False
  783.         Gr4.Draw
  784.         Gr4.Deleted = True
  785.         Grs.AddGraphic GrRes3
  786.     Else
  787.         GrIndex = Gr4.Index
  788.         Grs.Remove GrIndex
  789.         Gr.Graphics.AddGraphic Gr4
  790.         Gr4.Cosmetic = True
  791.         Set GrRes3 = GrRes2
  792.     End If
  793.     
  794. Dim GrRes4 As Graphic
  795.     GrRes3.Draw
  796. 'MsgBox ("111")
  797.     Set GrRes4 = Bool3D.Subtract(GrRes3, Gr5)
  798.     
  799.     If (Not GrRes4 Is Nothing) Then
  800.         GrRes3.Visible = False
  801.         GrRes3.Draw
  802.         GrRes3.Deleted = True
  803.         Gr5.Visible = False
  804.         Gr5.Draw
  805.         Gr5.Deleted = True
  806.         Grs.AddGraphic GrRes4
  807.         GrRes4.Draw
  808. Dim Matr As Matrix
  809.        
  810.         GrIndex = GrRes4.Index
  811.         Grs.Remove GrIndex
  812.         Gr.Graphics.AddGraphic GrRes4
  813.         GrRes4.Cosmetic = True
  814.         GrRes4.Properties("PenColor") = Gr.Properties("PenColor")
  815.         
  816. '????????????????????????????????????????????????????????????????
  817. Dim GrLine As Graphic
  818.         Set GrLine = Grs.Add(11)
  819.         GrLine.Vertices.UseWorldCS = True
  820.         With GrLine.Vertices
  821.             .Add 0, 0, 0
  822.             .Add H, 0, 0
  823.         End With
  824.         GrIndex = GrLine.Index
  825.         Grs.Remove GrIndex
  826.         Gr.Graphics.AddGraphic GrLine
  827.         GrLine.Cosmetic = True
  828. Dim xx0#, yy0#, zz0#, xx1#, yy1#, zz1#
  829.         GrLine.Vertices.UseWorldCS = False
  830.         With GrLine.Vertices
  831.             xx0 = .Item(0).X
  832.             yy0 = .Item(0).Y
  833.             zz0 = .Item(0).Z
  834.             xx1 = .Item(1).X
  835.             yy1 = .Item(1).Y
  836.             zz1 = .Item(1).Z
  837.         End With
  838.          Gr.Vertices.UseWorldCS = False
  839.         With Gr.Vertices
  840.             X00New = .Item(0).X
  841.             Y00New = .Item(0).Y
  842.             Z00New = .Item(0).Z
  843.         End With
  844.         GrRes4.MoveRelative X00New - xx0, Y00New - yy0, Z00New - zz0 '!!!!!!!
  845.         GrLine.Deleted = True
  846. '????????????????????????????????????????????????????????????????
  847.         
  848.     Else
  849.         GrIndex = Gr5.Index
  850.         Grs.Remove GrIndex
  851.         Gr.Graphics.AddGraphic Gr5
  852.         Gr5.Cosmetic = True
  853.         
  854.         Set GrRes4 = GrRes3
  855.         GrIndex = GrRes4.Index
  856.         Grs.Remove GrIndex
  857.         Gr.Graphics.AddGraphic GrRes4
  858.         GrRes4.Cosmetic = True
  859.     
  860.     End If
  861.     
  862.     Set Gr1 = Nothing
  863.     Set Gr2 = Nothing
  864.     Set Gr3 = Nothing
  865.     Set Gr4 = Nothing
  866.     Set Gr5 = Nothing
  867.     Set GrRes1 = Nothing
  868.     Set GrRes2 = Nothing
  869.     Set GrRes3 = Nothing
  870.     Set GrRes4 = Nothing
  871.     Set GrTemp = Nothing
  872.     Set Grs = Nothing
  873.     Set Bool3D = Nothing
  874.     
  875. Exit Sub
  876. Failed:
  877. End Sub
  878.  
  879. ' HexSlottedNut
  880.  
  881. Private Sub HexSlottedNut(Gr As Graphic, dd As Double, Salp As Double, Calp As Double, SSolid As Integer, AddScale As Double)
  882. On Error GoTo Failed
  883. Dim Grs As Graphics
  884.     Set Grs = Gr.Application.ActiveDrawing.Graphics
  885. Dim D#, H#, s#, del#
  886.         D = 1.84 * dd
  887.         H = 1# * dd
  888.         s = D * Cos(Pi / 6)
  889.         del = 0.1 * dd
  890. Dim J#
  891.         J = 0.2 * dd
  892.         Gr.Vertices.UseWorldCS = True
  893.         
  894. Dim X00#, Y00#, Z00#, X01#, Y01#, Z01#, L#
  895.         
  896.        With Gr.Vertices
  897.             X00 = .Item(0).X
  898.             Y00 = .Item(0).Y
  899.             Z00 = .Item(0).Z
  900.             X01 = .Item(1).X
  901.             Y01 = .Item(1).Y
  902.             Z01 = .Item(1).Z
  903.             L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00) + (Z01 - Z00) * (Z01 - Z00)) '!!!!!!!
  904.             .Item(1).X = X00 + (X01 - X00) * H / AddScale / L
  905.             .Item(1).Y = Y00 + (Y01 - Y00) * H / AddScale / L
  906.             .Item(1).Z = Z00 + (Z01 - Z00) * H / AddScale / L
  907.             X01 = X00 + (X01 - X00) * H / L '!!!!!!!
  908.             Y01 = Y00 + (Y01 - Y00) * H / L '!!!!!!!
  909.             Z01 = Z00 + (Z01 - Z00) * H / L '!!!!!!!
  910.         End With
  911.  
  912.         
  913. Dim X00New#, Y00New#, Z00New#, X01New#, Y01New#, Z01New#
  914.         X00New = X00    '!!!!!!!
  915.         Y00New = Y00    '!!!!!!!
  916.         Z00New = Z00    '!!!!!!!
  917.         X01New = X01    '!!!!!!!
  918.         Y01New = Y01    '!!!!!!!
  919.         Z01New = Z01    '!!!!!!!
  920.         X00 = 0#    '!!!!!!!
  921.         Y00 = 0#    '!!!!!!!
  922.         Z00 = 0#    '!!!!!!!
  923.         X01 = H    '!!!!!!!
  924.         Y01 = 0#    '!!!!!!!
  925.         Z01 = 0#    '!!!!!!!
  926.          
  927.         
  928. Dim x0(100)
  929. Dim y0(100)
  930. Dim X(100)
  931. Dim Y(100)
  932.        
  933.  
  934. Dim i As Long
  935. ' Head of the bolt
  936.     For i = 7 To 13
  937.         x0(i) = D / 2 * Cos(Pi / 3 * (i - 7))
  938.         y0(i) = D / 2 * Sin(Pi / 3 * (i - 7))
  939.     Next i
  940. Dim Gr1 As Graphic
  941. Set Gr1 = Grs.Add(gkGraphic)
  942. Gr1.Vertices.UseWorldCS = True
  943. With Gr1.Vertices
  944.     For i = 7 To 13
  945.         .Add x0(i), y0(i), 0, True, True, False, False, False, False
  946.     Next i
  947. End With
  948. Gr1.Closed = True
  949. Gr1.Properties("Thickness") = H
  950. Gr1.Properties("Solid") = SSolid
  951. Dim xTo#, yTo#, zTo#, xFrom#, yFrom#, zFrom#, xRef#, yRef#, zRef#
  952.     xTo = X00 + (X01 - X00) / H
  953.     yTo = Y00 + (Y01 - Y00) / H
  954.     zTo = 0
  955.     xFrom = X00
  956.     yFrom = Y00
  957.     zFrom = -1#
  958.     xRef = X00
  959.     yRef = Y00
  960.     zRef = 0#
  961.     Gr1.RotateAbsolute xTo, yTo, zTo, xFrom, yFrom, zFrom, xRef, yRef, zRef
  962.     Gr1.Draw
  963. '################################################################
  964. '################################################################
  965. Dim T#
  966.     T = D / 2 * Sin(Pi / 3)
  967.        x0(1) = -0.1 * H
  968.        y0(1) = T * 0.7 - 0.1 * H / Tan(Pi / 6)
  969.        
  970.        x0(2) = -0.1 * H
  971.        y0(2) = D
  972.        
  973.        x0(3) = 0.4 * H
  974.        y0(3) = D
  975.        
  976.        x0(4) = 0.4 * H
  977.        y0(4) = T * 0.7 + 0.5 * H / Tan(Pi / 6)
  978.        
  979.        x0(5) = x0(1)
  980.        y0(5) = y0(1)
  981.        
  982. '-----------------------------------------------------------
  983.        
  984. Dim GrTemp As Graphic
  985.             Set GrTemp = Grs.Add(gkGraphic)
  986.             GrTemp.Vertices.UseWorldCS = True
  987.             With GrTemp.Vertices
  988.                 For i = 1 To 5
  989.                     .Add x0(i), y0(i), 0
  990.                 Next i
  991.             End With
  992.             GrTemp.Closed = True
  993.             GrTemp.Draw
  994. Dim Gr2 As Graphic '1 faska
  995.             Set Gr2 = Grs.Add(, "TCW40SPIN")
  996.             Gr2.Vertices.UseWorldCS = True
  997.             Gr2.Properties("Solid") = SSolid
  998.             Gr2.Properties("$ROTATIONANGLE") = 2 * Pi
  999.             Gr2.Properties("$ROTATIONCOPY") = 30
  1000.             Set GrTemp = Grs.Remove(GrTemp.Index)
  1001.             Gr2.Graphics.AddGraphic GrTemp
  1002.             Gr2.Vertices.Add X00, Y00, 0, False, False, False, False, False
  1003.             Gr2.Vertices.Add X01, Y01, 0, False, False, False, False, False
  1004.             Gr2.Draw
  1005. Dim Gr3 As Graphic ' 2 faska
  1006.             Set Gr3 = Gr2.Duplicate
  1007.             Gr3.RotateAxis Pi, 0, 0, 1, X00, Y00, Z00
  1008.             Gr3.MoveRelative H, 0, 0
  1009.             Gr3.Draw
  1010. ' Internal Hole
  1011.        x0(1) = -del
  1012.        y0(1) = 0#
  1013.        
  1014.        x0(2) = -del
  1015.        y0(2) = dd / 2 + del
  1016.        
  1017.        x0(3) = del
  1018.        y0(3) = dd / 2 - del
  1019.        
  1020.        x0(4) = H - del
  1021.        y0(4) = dd / 2 - del
  1022.        
  1023.        x0(5) = H + del
  1024.        y0(5) = dd / 2 + del
  1025.        
  1026.        x0(6) = H + del
  1027.        y0(6) = 0
  1028.        
  1029.        x0(7) = x0(1)
  1030.        y0(7) = y0(1)
  1031.        
  1032. '-----------------------------------------------------------
  1033.        
  1034.             Set GrTemp = Grs.Add(gkGraphic)
  1035.             GrTemp.Vertices.UseWorldCS = True
  1036.             With GrTemp.Vertices
  1037.                 For i = 1 To 7
  1038.                     .Add x0(i), y0(i), 0
  1039.                 Next i
  1040.             End With
  1041.             GrTemp.Closed = True
  1042. Dim Gr4 As Graphic
  1043.             Set Gr4 = Grs.Add(, "TCW40SPIN")
  1044.             Gr4.Vertices.UseWorldCS = True
  1045.             Gr4.Properties("Solid") = SSolid
  1046.             Gr4.Properties("$ROTATIONANGLE") = 2 * Pi
  1047.             Gr4.Properties("$ROTATIONCOPY") = 30
  1048.             Set GrTemp = Grs.Remove(GrTemp.Index)
  1049.             Gr4.Graphics.AddGraphic GrTemp
  1050.             Gr4.Vertices.Add X00, Y00, 0, False, False, False, False, False
  1051.             Gr4.Vertices.Add X01, Y01, 0, False, False, False, False, False
  1052.             Gr4.Draw
  1053.  
  1054. ' Thread
  1055.     'Base contour
  1056. Dim hThread# ' Step of the thread
  1057.     hThread = del / Sin(Pi / 3)
  1058. Dim nCoil As Long
  1059.     nCoil = 10
  1060.     nCoil = CLng(H / hThread) + 3
  1061. Dim lThread#
  1062.     lThread = nCoil * hThread
  1063. Dim k As Long
  1064.     
  1065.     x0(1) = 0#
  1066.     y0(1) = 0#
  1067.     
  1068.     x0(2) = 0#
  1069.     y0(2) = dd / 2 - del
  1070.     
  1071.     k = 2
  1072.     
  1073.     For i = 1 To nCoil
  1074.         k = k + 1
  1075.         x0(k) = x0(k - 1) + hThread / 2
  1076.         y0(k) = y0(k - 1) + del
  1077.         k = k + 1
  1078.         x0(k) = x0(k - 1) + hThread / 2
  1079.         y0(k) = y0(k - 1) - del
  1080.     Next i
  1081.     k = k + 1
  1082.     x0(k) = x0(k - 1)
  1083.     y0(k) = 0
  1084.     
  1085.     k = k + 1
  1086.     x0(k) = 0
  1087.     y0(k) = 0
  1088.  
  1089.  
  1090. Set GrTemp = Grs.Add(gkGraphic)
  1091. GrTemp.Vertices.UseWorldCS = True
  1092. With GrTemp.Vertices
  1093.     For i = 1 To k '6
  1094.         .Add x0(i), y0(i), 0
  1095.     Next i
  1096. End With
  1097. GrTemp.Closed = True
  1098. GrTemp.MoveRelative -hThread, 0, 0
  1099. GrTemp.Draw
  1100.  
  1101. Dim Gr5 As Graphic
  1102. Set Gr5 = Grs.Add(, "TCW40SPIN")
  1103. Gr5.Vertices.UseWorldCS = True
  1104. Gr5.Properties("Solid") = SSolid
  1105. Gr5.Properties("$ROTATIONANGLE") = 2 * Pi
  1106. Gr5.Properties("$ROTATIONCOPY") = 30
  1107. Set GrTemp = Grs.Remove(GrTemp.Index)
  1108. Gr5.Graphics.AddGraphic GrTemp
  1109. Gr5.Vertices.Add X00, Y00, 0, False, False, False, False, False
  1110. Gr5.Vertices.Add X01, Y01, 0, False, False, False, False, False
  1111. Gr5.Draw
  1112.  
  1113. ' First Slot
  1114. Dim fi#, dfi#
  1115.     dfi = Pi / 9#
  1116.     x0(1) = H + 0.1 * J
  1117.     y0(1) = -J / 2
  1118.     
  1119.     x0(2) = H + 0.1 * J
  1120.     y0(2) = J / 2
  1121.     
  1122.     x0(3) = x0(1) - J
  1123.     y0(3) = J / 2
  1124.     
  1125.     For i = 1 To 8
  1126.         x0(i + 3) = x0(3) + J / 2 * Cos(Pi / 2# + i * dfi)
  1127.         y0(i + 3) = J / 2 * Sin(Pi / 2# - i * dfi)
  1128.     Next i
  1129.     
  1130.     x0(12) = x0(3)
  1131.     y0(12) = -J / 2
  1132.     
  1133.     x0(13) = x0(1)
  1134.     y0(13) = y0(1)
  1135.     
  1136. Dim Gr6 As Graphic
  1137.     Set Gr6 = Grs.Add(gkGraphic)
  1138.     Gr6.Vertices.UseWorldCS = True
  1139.     With Gr6.Vertices
  1140.         For i = 1 To 13
  1141.             .Add x0(i), y0(i), 0
  1142.         Next i
  1143.     End With
  1144.     Gr6.Closed = True
  1145.     Gr6.MoveRelative 0, 0, -D
  1146.     Gr6.Properties("Thickness") = 2 * D
  1147.     Gr6.Properties("Solid") = SSolid
  1148.         
  1149. Dim dx#, dy#
  1150.     L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00) + (Z01 - Z00) * (Z01 - Z00))
  1151.     dx = (X01 - X00) / L
  1152.     dy = (Y01 - Y00) / L
  1153.     Gr6.RotateAxis Pi / 6, dx, dy, 0, X00, Y00, Z00
  1154.     Gr6.Draw
  1155.     
  1156. Dim Gr7 As Graphic
  1157.     Set Gr7 = Gr6.Duplicate
  1158.     Gr7.RotateAxis Pi / 3, dx, dy, 0, X00, Y00, Z00
  1159.     Gr7.Draw
  1160.     
  1161. Dim Gr8 As Graphic
  1162.     Set Gr8 = Gr7.Duplicate
  1163.     Gr8.RotateAxis Pi / 3, dx, dy, 0, X00, Y00, Z00
  1164.     Gr8.Draw
  1165. 'MsgBox ("1111")
  1166. '#################################################################
  1167. '################################################################
  1168. Dim Bool3D As Boolean3D
  1169. Dim GrRes1 As Graphic
  1170. Dim GrIndex As Long
  1171.     Set Bool3D = New Boolean3D
  1172.     Gr1.Draw
  1173.     Gr2.Draw
  1174.     Set GrRes1 = Bool3D.Subtract(Gr1, Gr2)
  1175.     If (Not GrRes1 Is Nothing) Then
  1176.         Gr1.Visible = False
  1177.         Gr1.Draw
  1178.         Gr1.Deleted = True
  1179.         Gr2.Visible = False
  1180.         Gr2.Draw
  1181.         Gr2.Deleted = True
  1182.         Grs.AddGraphic GrRes1
  1183.     Else
  1184.         GrIndex = Gr2.Index
  1185.         Grs.Remove GrIndex
  1186.         Gr.Graphics.AddGraphic Gr2
  1187.         Gr2.Cosmetic = True
  1188.         Set GrRes1 = Gr1
  1189.     End If
  1190. Dim GrRes2 As Graphic
  1191.     GrRes1.Draw
  1192.     Set GrRes2 = Bool3D.Subtract(GrRes1, Gr3)
  1193.     If (Not GrRes2 Is Nothing) Then
  1194.         GrRes1.Visible = False
  1195.         GrRes1.Draw
  1196.         GrRes1.Deleted = True
  1197.         Gr3.Visible = False
  1198.         Gr3.Draw
  1199.         Gr3.Deleted = True
  1200.         Grs.AddGraphic GrRes2
  1201.     Else
  1202.         GrIndex = Gr3.Index
  1203.         Grs.Remove GrIndex
  1204.         Gr.Graphics.AddGraphic Gr3
  1205.         Gr3.Cosmetic = True
  1206.         Set GrRes2 = GrRes1
  1207.     End If
  1208.     
  1209. Dim GrRes3 As Graphic
  1210.     GrRes2.Draw
  1211.     Set GrRes3 = Bool3D.Subtract(GrRes2, Gr4)
  1212.     If (Not GrRes3 Is Nothing) Then
  1213.         GrRes2.Visible = False
  1214.         GrRes2.Draw
  1215.         GrRes2.Deleted = True
  1216.         Gr4.Visible = False
  1217.         Gr4.Draw
  1218.         Gr4.Deleted = True
  1219.         Grs.AddGraphic GrRes3
  1220.     Else
  1221.         GrIndex = Gr4.Index
  1222.         Grs.Remove GrIndex
  1223.         Gr.Graphics.AddGraphic Gr4
  1224.         Gr4.Cosmetic = True
  1225.         Set GrRes3 = GrRes2
  1226.     End If
  1227.     
  1228. ' Work with slots
  1229. Dim GrRes5 As Graphic
  1230.     GrRes3.Draw
  1231.     Set GrRes5 = Bool3D.Subtract(GrRes3, Gr6)
  1232.     If (Not GrRes5 Is Nothing) Then
  1233.         GrRes3.Visible = False
  1234.         GrRes3.Draw
  1235.         GrRes3.Deleted = True
  1236.         Gr6.Visible = False
  1237.         Gr6.Draw
  1238.         Gr6.Deleted = True
  1239.         Grs.AddGraphic GrRes5
  1240.     Else
  1241.         GrIndex = Gr6.Index
  1242.         Grs.Remove GrIndex
  1243.         Gr.Graphics.AddGraphic Gr6
  1244.         Gr6.Cosmetic = True
  1245.         Set GrRes5 = GrRes3
  1246.     End If
  1247.     
  1248. Dim GrRes6 As Graphic
  1249.     GrRes5.Draw
  1250.     Set GrRes6 = Bool3D.Subtract(GrRes5, Gr7)
  1251.     If (Not GrRes6 Is Nothing) Then
  1252.         GrRes5.Visible = False
  1253.         GrRes5.Draw
  1254.         GrRes5.Deleted = True
  1255.         Gr7.Visible = False
  1256.         Gr7.Draw
  1257.         Gr7.Deleted = True
  1258.         Grs.AddGraphic GrRes6
  1259.     Else
  1260.         GrIndex = Gr7.Index
  1261.         Grs.Remove GrIndex
  1262.         Gr.Graphics.AddGraphic Gr7
  1263.         Gr7.Cosmetic = True
  1264.         Set GrRes6 = GrRes5
  1265.     End If
  1266.     
  1267. Dim GrRes7 As Graphic
  1268.     GrRes6.Draw
  1269.     Set GrRes7 = Bool3D.Subtract(GrRes6, Gr8)
  1270.     If (Not GrRes7 Is Nothing) Then
  1271.         GrRes6.Visible = False
  1272.         GrRes6.Draw
  1273.         GrRes6.Deleted = True
  1274.         Gr8.Visible = False
  1275.         Gr8.Draw
  1276.         Gr8.Deleted = True
  1277.         Grs.AddGraphic GrRes7
  1278.     Else
  1279.         GrIndex = Gr8.Index
  1280.         Grs.Remove GrIndex
  1281.         Gr.Graphics.AddGraphic Gr8
  1282.         Gr8.Cosmetic = True
  1283.         Set GrRes7 = GrRes6
  1284.     End If
  1285.  
  1286. ' End with slots
  1287. Dim GrRes4 As Graphic
  1288.     GrRes7.Draw
  1289.     Set GrRes4 = Bool3D.Subtract(GrRes7, Gr5)
  1290.     If (Not GrRes4 Is Nothing) Then
  1291.         GrRes7.Visible = False
  1292.         GrRes7.Draw
  1293.         GrRes7.Deleted = True
  1294.         Gr5.Visible = False
  1295.         Gr5.Draw
  1296.         Gr5.Deleted = True
  1297.         Grs.AddGraphic GrRes4
  1298. Dim Matr As Matrix
  1299.         GrIndex = GrRes4.Index
  1300.         Grs.Remove GrIndex
  1301.         Gr.Graphics.AddGraphic GrRes4
  1302.         GrRes4.Cosmetic = True
  1303.         GrRes4.Properties("PenColor") = Gr.Properties("PenColor")
  1304. '????????????????????????????????????????????????????????????????
  1305. Dim GrLine As Graphic
  1306.         Set GrLine = Grs.Add(11)
  1307.         GrLine.Vertices.UseWorldCS = True
  1308.         With GrLine.Vertices
  1309.             .Add 0, 0, 0
  1310.             .Add H, 0, 0
  1311.         End With
  1312.         GrIndex = GrLine.Index
  1313.         Grs.Remove GrIndex
  1314.         Gr.Graphics.AddGraphic GrLine
  1315.         GrLine.Cosmetic = True
  1316. Dim xx0#, yy0#, zz0#, xx1#, yy1#, zz1#
  1317.         GrLine.Vertices.UseWorldCS = False
  1318.         With GrLine.Vertices
  1319.             xx0 = .Item(0).X
  1320.             yy0 = .Item(0).Y
  1321.             zz0 = .Item(0).Z
  1322.             xx1 = .Item(1).X
  1323.             yy1 = .Item(1).Y
  1324.             zz1 = .Item(1).Z
  1325.         End With
  1326.          Gr.Vertices.UseWorldCS = False
  1327.         With Gr.Vertices
  1328.             X00New = .Item(0).X
  1329.             Y00New = .Item(0).Y
  1330.             Z00New = .Item(0).Z
  1331.         End With
  1332.         GrRes4.MoveRelative X00New - xx0, Y00New - yy0, Z00New - zz0 '!!!!!!!
  1333.         GrLine.Deleted = True
  1334. '????????????????????????????????????????????????????????????????
  1335.     Else
  1336.         GrIndex = Gr5.Index
  1337.         Grs.Remove GrIndex
  1338.         Gr.Graphics.AddGraphic Gr5
  1339.         Gr5.Cosmetic = True
  1340.         
  1341.         Set GrRes4 = GrRes5
  1342.         GrIndex = GrRes4.Index
  1343.         Grs.Remove GrIndex
  1344.         Gr.Graphics.AddGraphic GrRes4
  1345.         GrRes4.Cosmetic = True
  1346.     
  1347.     End If
  1348.  
  1349.     Set Gr1 = Nothing
  1350.     Set Gr2 = Nothing
  1351.     Set Gr3 = Nothing
  1352.     Set Gr4 = Nothing
  1353.     Set Gr5 = Nothing
  1354.     Set Gr6 = Nothing
  1355.     Set Gr7 = Nothing
  1356.     Set Gr8 = Nothing
  1357.     Set GrRes1 = Nothing
  1358.     Set GrRes2 = Nothing
  1359.     Set GrRes3 = Nothing
  1360.     Set GrRes4 = Nothing
  1361.     Set GrRes5 = Nothing
  1362.     Set GrRes6 = Nothing
  1363.     Set GrRes7 = Nothing
  1364.     Set GrTemp = Nothing
  1365.     Set Grs = Nothing
  1366.     Set Bool3D = Nothing
  1367.     
  1368. Exit Sub
  1369. Failed:
  1370. End Sub
  1371.  
  1372.  
  1373. ' LowCrownNut
  1374.  
  1375. Private Sub LowCrownNut(Gr As Graphic, dd As Double, Salp As Double, Calp As Double, SSolid As Integer, AddScale As Double)
  1376. On Error GoTo Failed
  1377. Dim Grs As Graphics
  1378.     Set Grs = Gr.Application.ActiveDrawing.Graphics
  1379. Dim D#, H#, s#, del#
  1380.         D = 1.84 * dd
  1381.         H = 0.7 * dd
  1382.         s = D * Cos(Pi / 6)
  1383.         del = 0.1 * dd
  1384.         
  1385.         Gr.Vertices.UseWorldCS = True
  1386.         
  1387. Dim X00#, Y00#, Z00#, X01#, Y01#, Z01#, L#
  1388.         
  1389.        With Gr.Vertices
  1390.             X00 = .Item(0).X
  1391.             Y00 = .Item(0).Y
  1392.             Z00 = .Item(0).Z
  1393.             X01 = .Item(1).X
  1394.             Y01 = .Item(1).Y
  1395.             Z01 = .Item(1).Z
  1396.             L = Sqr((X01 - X00) * (X01 - X00) + (Y01 - Y00) * (Y01 - Y00) + (Z01 - Z00) * (Z01 - Z00)) '!!!!!!!
  1397.             .Item(1).X = X00 + (X01 - X00) * H / AddScale / L
  1398.             .Item(1).Y = Y00 + (Y01 - Y00) * H / AddScale / L
  1399.             .Item(1).Z = Z00 + (Z01 - Z00) * H / AddScale / L
  1400.             X01 = X00 + (X01 - X00) * H / L '!!!!!!!
  1401.             Y01 = Y00 + (Y01 - Y00) * H / L '!!!!!!!
  1402.             Z01 = Z00 + (Z01 - Z00) * H / L '!!!!!!!
  1403.         End With
  1404.         
  1405. Dim X00New#, Y00New#, Z00New#, X01New#, Y01New#, Z01New#
  1406.         X00New = X00    '!!!!!!!
  1407.         Y00New = Y00    '!!!!!!!
  1408.         Z00New = Z00    '!!!!!!!
  1409.         X01New = X01    '!!!!!!!
  1410.         Y01New = Y01    '!!!!!!!
  1411.         Z01New = Z01    '!!!!!!!
  1412.         X00 = 0#    '!!!!!!!
  1413.         Y00 = 0#    '!!!!!!!
  1414.         Z00 = 0#    '!!!!!!!
  1415.         X01 = H    '!!!!!!!
  1416.         Y01 = 0#    '!!!!!!!
  1417.         Z01 = 0#    '!!!!!!!
  1418.         
  1419. Dim x0(100)
  1420. Dim y0(100)
  1421. Dim X(100)
  1422. Dim Y(100)
  1423.  
  1424. Dim i As Long
  1425. ' Head of the bolt
  1426.     For i = 7 To 13
  1427.         x0(i) = D / 2 * Cos(Pi / 3 * (i - 7))
  1428.         y0(i) = D / 2 * Sin(Pi / 3 * (i - 7))
  1429.     Next i
  1430. Dim Gr1 As Graphic
  1431. Set Gr1 = Grs.Add(gkGraphic)
  1432. Gr1.Vertices.UseWorldCS = True
  1433. With Gr1.Vertices
  1434.     For i = 7 To 13
  1435.         .Add x0(i), y0(i), 0, True, True, False, False, False, False
  1436.     Next i
  1437. End With
  1438. Gr1.Closed = True
  1439. Gr1.Properties("Thickness") = H
  1440. Gr1.Properties("Solid") = SSolid
  1441. Dim xTo#, yTo#, zTo#, xFrom#, yFrom#, zFrom#, xRef#, yRef#, zRef#
  1442.     xTo = X00 + (X01 - X00) / H
  1443.     yTo = Y00 + (Y01 - Y00) / H
  1444.     zTo = 0
  1445.     xFrom = X00
  1446.     yFrom = Y00
  1447.     zFrom = -1#
  1448.     xRef = X00
  1449.     yRef = Y00
  1450.     zRef = 0#
  1451.     Gr1.RotateAbsolute xTo, yTo, zTo, xFrom, yFrom, zFrom, xRef, yRef, zRef
  1452. '################################################################
  1453. '################################################################
  1454. Dim T#
  1455.     T = D / 2 * Sin(Pi / 3)
  1456.        x0(1) = -0.1 * H
  1457.        y0(1) = T * 0.7 - 0.1 * H / Tan(Pi / 6)
  1458.        
  1459.        x0(2) = -0.1 * H
  1460.        y0(2) = D
  1461.        
  1462.        x0(3) = 0.4 * H
  1463.        y0(3) = D
  1464.        
  1465.        x0(4) = 0.4 * H
  1466.        y0(4) = T * 0.7 + 0.5 * H / Tan(Pi / 6)
  1467.        
  1468.        x0(5) = x0(1)
  1469.        y0(5) = y0(1)
  1470.        
  1471. '-----------------------------------------------------------
  1472.        
  1473. Dim GrTemp As Graphic
  1474.             Set GrTemp = Grs.Add(gkGraphic)
  1475.             GrTemp.Vertices.UseWorldCS = True
  1476.             With GrTemp.Vertices
  1477.                 For i = 1 To 5
  1478.                     .Add x0(i), y0(i), 0
  1479.                 Next i
  1480.             End With
  1481.             GrTemp.Closed = True
  1482. Dim Gr2 As Graphic '1 faska
  1483.             Set Gr2 = Grs.Add(, "TCW40SPIN")
  1484.             Gr2.Vertices.UseWorldCS = True
  1485.             Gr2.Properties("Solid") = SSolid
  1486.             Gr2.Properties("$ROTATIONANGLE") = 2 * Pi
  1487.             Gr2.Properties("$ROTATIONCOPY") = 30
  1488.             Set GrTemp = Grs.Remove(GrTemp.Index)
  1489.             Gr2.Graphics.AddGraphic GrTemp
  1490.             Gr2.Vertices.Add X00, Y00, 0, False, False, False, False, False
  1491.             Gr2.Vertices.Add X01, Y01, 0, False, False, False, False, False
  1492. Dim Gr3 As Graphic ' 2 faska
  1493.             Set Gr3 = Gr2.Duplicate
  1494.             Gr3.RotateAxis Pi, 0, 0, 1, X00, Y00, Z00
  1495.             Gr3.MoveRelative H, 0, 0
  1496.  
  1497. ' Internal Hole
  1498.        x0(1) = -del
  1499.        y0(1) = 0#
  1500.        
  1501.        x0(2) = -del
  1502.        y0(2) = dd / 2 + del
  1503.        
  1504.        x0(3) = del
  1505.        y0(3) = dd / 2 - del
  1506.        
  1507.        x0(4) = 1.3 * H - del
  1508.        y0(4) = dd / 2 - del
  1509.        
  1510.        x0(5) = 1.3 * H + del
  1511.        y0(5) = dd / 2 + del
  1512.        
  1513.        x0(6) = 1.3 * H + del
  1514.        y0(6) = 0
  1515.        
  1516.        x0(7) = x0(1)
  1517.        y0(7) = y0(1)
  1518.        
  1519. '-----------------------------------------------------------
  1520.        
  1521.             Set GrTemp = Grs.Add(gkGraphic)
  1522.             GrTemp.Vertices.UseWorldCS = True
  1523.             With GrTemp.Vertices
  1524.                 For i = 1 To 7
  1525.                     .Add x0(i), y0(i), 0
  1526.                 Next i
  1527.             End With
  1528.             GrTemp.Closed = True
  1529. Dim Gr4 As Graphic
  1530.             Set Gr4 = Grs.Add(, "TCW40SPIN")
  1531.             Gr4.Vertices.UseWorldCS = True
  1532.             Gr4.Properties("Solid") = SSolid
  1533.             Gr4.Properties("$ROTATIONANGLE") = 2 * Pi
  1534.             Gr4.Properties("$ROTATIONCOPY") = 30
  1535.             Set GrTemp = Grs.Remove(GrTemp.Index)
  1536.             Gr4.Graphics.AddGraphic GrTemp
  1537.             Gr4.Vertices.Add X00, Y00, 0, False, False, False, False, False
  1538.             Gr4.Vertices.Add X01, Y01, 0, False, False, False, False, False
  1539.  
  1540.  
  1541. ' Thread
  1542.     'Base contour
  1543. Dim hThread# ' Step of the thread
  1544.     hThread = del / Sin(Pi / 3)
  1545. Dim nCoil As Long
  1546.     nCoil = 10
  1547.     nCoil = CLng(H / hThread) + 2
  1548.     
  1549. Dim lThread#
  1550.     lThread = nCoil * hThread
  1551. Dim k As Long
  1552.     
  1553.     x0(1) = 0#
  1554.     y0(1) = 0#
  1555.     
  1556.     x0(2) = 0#
  1557.     y0(2) = dd / 2 - del
  1558.     
  1559.     k = 2
  1560.     
  1561.     For i = 1 To nCoil
  1562.         k = k + 1
  1563.         x0(k) = x0(k - 1) + hThread / 2
  1564.         y0(k) = y0(k - 1) + del
  1565.         k = k + 1
  1566.         x0(k) = x0(k - 1) + hThread / 2
  1567.         y0(k) = y0(k - 1) - del
  1568.     Next i
  1569.     k = k + 1
  1570.     x0(k) = lThread
  1571.     y0(k) = 0
  1572.     
  1573.     k = k + 1
  1574.     x0(k) = 0
  1575.     y0(k) = 0
  1576.  
  1577. Set GrTemp = Grs.Add(gkGraphic)
  1578. GrTemp.Vertices.UseWorldCS = True
  1579. With GrTemp.Vertices
  1580.     For i = 1 To k '6
  1581.         .Add x0(i), y0(i), 0
  1582.     Next i
  1583. End With
  1584. GrTemp.Closed = True
  1585.  
  1586. Dim Gr5 As Graphic
  1587. Set Gr5 = Grs.Add(, "TCW40SPIN")
  1588. Gr5.Vertices.UseWorldCS = True
  1589. Gr5.Properties("Solid") = SSolid
  1590. Gr5.Properties("$ROTATIONANGLE") = 2 * Pi
  1591. Gr5.Properties("$ROTATIONCOPY") = 30
  1592. Set GrTemp = Grs.Remove(GrTemp.Index)
  1593. Gr5.Graphics.AddGraphic GrTemp
  1594. Gr5.Vertices.Add X00, Y00, 0, False, False, False, False, False
  1595. Gr5.Vertices.Add X01, Y01, 0, False, False, False, False, False
  1596.  
  1597. 'Crown
  1598. Dim fi#, dfi#
  1599.         dfi = Pi / 2 / 20
  1600.        x0(1) = 0.8 * H
  1601.        y0(1) = 0#
  1602.        
  1603.        x0(2) = 0.8 * H
  1604.        y0(2) = 0.9 * s / 2#
  1605.        
  1606.        x0(3) = H
  1607.        y0(3) = 0.9 * s / 2#
  1608. Dim m%
  1609.         m = 3
  1610.        For i = 1 To 20
  1611.             m = m + 1
  1612.             fi = Pi / 2 - i * dfi
  1613.             x0(m) = H + 0.9 * s / 2 * Cos(fi)
  1614.             y0(m) = 0.9 * s / 2 * Sin(fi)
  1615.        Next i
  1616.        m = m + 1
  1617.        x0(m) = x0(1)
  1618.        y0(m) = y0(1)
  1619.        
  1620.        
  1621. '-----------------------------------------------------------
  1622.        
  1623.             Set GrTemp = Grs.Add(gkGraphic)
  1624.             GrTemp.Vertices.UseWorldCS = True
  1625.             With GrTemp.Vertices
  1626.                 For i = 1 To m
  1627.                     .Add x0(i), y0(i), 0
  1628.                 Next i
  1629.             End With
  1630.             GrTemp.Closed = True
  1631.  
  1632. Dim Gr6 As Graphic
  1633.             Set Gr6 = Grs.Add(, "TCW40SPIN")
  1634.             Gr6.Vertices.UseWorldCS = True
  1635.             Gr6.Properties("Solid") = SSolid
  1636.             Gr6.Properties("$ROTATIONANGLE") = 2 * Pi
  1637.             Gr6.Properties("$ROTATIONCOPY") = 30
  1638.             Set GrTemp = Grs.Remove(GrTemp.Index)
  1639.             Gr6.Graphics.AddGraphic GrTemp
  1640.             Gr6.Vertices.Add X00, Y00, 0, False, False, False, False, False
  1641.             Gr6.Vertices.Add X01, Y01, 0, False, False, False, False, False
  1642.  
  1643.  
  1644.  
  1645. '#################################################################
  1646. '################################################################
  1647. Dim Bool3D As Boolean3D
  1648. Dim GrRes1 As Graphic
  1649. Dim GrIndex As Long
  1650.     Set Bool3D = New Boolean3D
  1651.     Gr1.Update
  1652.     Gr2.Update
  1653.     Set GrRes1 = Bool3D.Subtract(Gr1, Gr2)
  1654.     If (Not GrRes1 Is Nothing) Then
  1655.         Gr1.Deleted = True
  1656.         Gr2.Deleted = True
  1657.         Grs.AddGraphic GrRes1
  1658.     Else
  1659.         GrIndex = Gr2.Index
  1660.         Grs.Remove GrIndex
  1661.         Gr.Graphics.AddGraphic Gr2
  1662.         Gr2.Cosmetic = True
  1663.         Set GrRes1 = Gr1
  1664.     End If
  1665. Dim GrRes2 As Graphic
  1666.     GrRes1.Update
  1667.     Gr3.Update
  1668.     Set GrRes2 = Bool3D.Subtract(GrRes1, Gr3)
  1669.     If (Not GrRes2 Is Nothing) Then
  1670.         GrRes1.Deleted = True
  1671.         Gr3.Deleted = True
  1672.         Grs.AddGraphic GrRes2
  1673.     Else
  1674.         GrIndex = Gr3.Index
  1675.         Grs.Remove GrIndex
  1676.         Gr.Graphics.AddGraphic Gr3
  1677.         Gr3.Cosmetic = True
  1678.         Set GrRes2 = GrRes1
  1679.     End If
  1680.     
  1681. Dim GrRes5 As Graphic
  1682.     GrRes2.Update
  1683.     Gr6.Update
  1684.     Set GrRes5 = Bool3D.Add(GrRes2, Gr6)
  1685.     If (Not GrRes5 Is Nothing) Then
  1686.         GrRes2.Deleted = True
  1687.         Gr6.Deleted = True
  1688.         Grs.AddGraphic GrRes5
  1689.     Else
  1690.         GrIndex = Gr6.Index
  1691.         Grs.Remove GrIndex
  1692.         Gr.Graphics.AddGraphic Gr6
  1693.         Gr6.Cosmetic = True
  1694.         Set GrRes5 = GrRes2
  1695.     End If
  1696.     
  1697.     
  1698. Dim GrRes3 As Graphic
  1699.     GrRes5.Update
  1700.     Gr4.Update
  1701.     Set GrRes3 = Bool3D.Subtract(GrRes5, Gr4)
  1702.     If (Not GrRes3 Is Nothing) Then
  1703.         GrRes5.Deleted = True
  1704.         Gr4.Deleted = True
  1705.         Grs.AddGraphic GrRes3
  1706.     Else
  1707.         GrIndex = Gr4.Index
  1708.         Grs.Remove GrIndex
  1709.         Gr.Graphics.AddGraphic Gr4
  1710.         Gr4.Cosmetic = True
  1711.         Set GrRes3 = GrRes5
  1712.     End If
  1713.     
  1714. Dim GrRes4 As Graphic
  1715.     GrRes3.Update
  1716.     Gr5.Update
  1717.     Set GrRes4 = Bool3D.Subtract(GrRes3, Gr5)
  1718.     If (Not GrRes4 Is Nothing) Then
  1719.         GrRes3.Deleted = True
  1720.         Gr5.Deleted = True
  1721.         Grs.AddGraphic GrRes4
  1722.         
  1723.         GrIndex = GrRes4.Index
  1724.         Grs.Remove GrIndex
  1725.         Gr.Graphics.AddGraphic GrRes4
  1726.         GrRes4.Cosmetic = True
  1727.         GrRes4.Properties("PenColor") = Gr.Properties("PenColor")
  1728.  '????????????????????????????????????????????????????????????????
  1729. Dim GrLine As Graphic
  1730.         Set GrLine = Grs.Add(11)
  1731.         GrLine.Vertices.UseWorldCS = True
  1732.         With GrLine.Vertices
  1733.             .Add 0, 0, 0
  1734.             .Add H, 0, 0
  1735.         End With
  1736.         GrIndex = GrLine.Index
  1737.         Grs.Remove GrIndex
  1738.         Gr.Graphics.AddGraphic GrLine
  1739.         GrLine.Cosmetic = True
  1740. Dim xx0#, yy0#, zz0#, xx1#, yy1#, zz1#
  1741.         GrLine.Vertices.UseWorldCS = False
  1742.         With GrLine.Vertices
  1743.             xx0 = .Item(0).X
  1744.             yy0 = .Item(0).Y
  1745.             zz0 = .Item(0).Z
  1746.             xx1 = .Item(1).X
  1747.             yy1 = .Item(1).Y
  1748.             zz1 = .Item(1).Z
  1749.         End With
  1750.          Gr.Vertices.UseWorldCS = False
  1751.         With Gr.Vertices
  1752.             X00New = .Item(0).X
  1753.             Y00New = .Item(0).Y
  1754.             Z00New = .Item(0).Z
  1755.         End With
  1756.         GrRes4.MoveRelative X00New - xx0, Y00New - yy0, Z00New - zz0 '!!!!!!!
  1757.         GrLine.Deleted = True
  1758. '????????????????????????????????????????????????????????????????
  1759.    
  1760.     Else
  1761.         GrIndex = Gr5.Index
  1762.         Grs.Remove GrIndex
  1763.         Gr.Graphics.AddGraphic Gr5
  1764.         Gr5.Cosmetic = True
  1765.         
  1766.         Set GrRes4 = GrRes3
  1767.         GrIndex = GrRes4.Index
  1768.         Grs.Remove GrIndex
  1769.         Gr.Graphics.AddGraphic GrRes4
  1770.         GrRes4.Cosmetic = True
  1771.     
  1772.     End If
  1773.  
  1774.     Set Gr1 = Nothing
  1775.     Set Gr2 = Nothing
  1776.     Set Gr3 = Nothing
  1777.     Set Gr4 = Nothing
  1778.     Set Gr5 = Nothing
  1779.     Set Gr6 = Nothing
  1780.     Set GrRes1 = Nothing
  1781.     Set GrRes2 = Nothing
  1782.     Set GrRes3 = Nothing
  1783.     Set GrRes4 = Nothing
  1784.     Set GrRes5 = Nothing
  1785.     Set GrTemp = Nothing
  1786.     Set Grs = Nothing
  1787.     Set Bool3D = Nothing
  1788.     
  1789. Exit Sub
  1790. Failed:
  1791. End Sub
  1792.  
  1793.  
  1794. 'defines the distance frof line to point in 3D space
  1795. Private Function DistPointLine(x0 As Double, y0 As Double, z0 As Double, x1 As Double, y1 As Double, z1 As Double, x2 As Double, y2 As Double, z2 As Double) As Double
  1796.     
  1797. Dim l1#, m1#, n1#
  1798.         l1 = x2 - x1
  1799.         m1 = y2 - y1
  1800.         n1 = z2 - z1
  1801. Dim t1#, t2#, t3#
  1802.         t1 = (y0 - y1) * n1 - (z0 - z1) * m1
  1803.         t2 = (z0 - z1) * l1 - (x0 - x1) * n1
  1804.         t3 = (x0 - x1) * m1 - (y0 - y1) * l1
  1805. Dim s0#, s1#, s2#
  1806.         s1 = Sqr(t1 * t1 + t2 * t2 + t3 * t3)
  1807.         s2 = Sqr(l1 * l1 + m1 * m1 + n1 * n1)
  1808.         DistPointLine = s1 / s2
  1809. End Function
  1810.  
  1811.  
  1812.